<html>
<head><meta charset="utf-8"><title>PSA: we now can count things · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html">PSA: we now can count things</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="223533311"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223533311" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223533311">(Jan 21 2021 at 16:26)</a>:</h4>
<p>Curious what do you think about <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7378">https://github.com/rust-analyzer/rust-analyzer/pull/7378</a> ?</p>



<a name="223533465"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223533465" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223533465">(Jan 21 2021 at 16:27)</a>:</h4>
<p>I like it's zero cost nature --- even counting names doesn't slow things down. Although the perf with <code>RA_COUNT=1</code> is noticiably slower.</p>



<a name="223533812"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223533812" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223533812">(Jan 21 2021 at 16:30)</a>:</h4>
<p>cc <span class="user-mention" data-user-id="211727">@Jonas Schievink</span> -- might be handy for tracking memory use</p>



<a name="223534666"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223534666" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223534666">(Jan 21 2021 at 16:36)</a>:</h4>
<p>What's the difference between the <code>max_live</code> loop and <code>fetch_max</code>?</p>



<a name="223535760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223535760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223535760">(Jan 21 2021 at 16:42)</a>:</h4>
<p>And should the <code>cfg</code> be put on the <code>impl</code> in <a href="https://github.com/matklad/countme/blob/master/src/lib.rs#L97">https://github.com/matklad/countme/blob/master/src/lib.rs#L97</a> to avoid having an empty <code>drop</code> when it's disabled at build-time?</p>



<a name="223539394"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223539394" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223539394">(Jan 21 2021 at 17:06)</a>:</h4>
<blockquote>
<p>What's the difference between the max_live loop and fetch_max?</p>
</blockquote>



<a name="223539422"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223539422" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223539422">(Jan 21 2021 at 17:06)</a>:</h4>
<p>TIL, thanks!</p>



<a name="223540385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223540385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223540385">(Jan 21 2021 at 17:12)</a>:</h4>
<blockquote>
<p>And should the cfg be put on the impl in <a href="https://github.com/matklad/countme/blob/master/src/lib.rs#L97">https://github.com/matklad/countme/blob/master/src/lib.rs#L97</a> to avoid having an empty drop when it's disabled at build-time?</p>
</blockquote>
<p>I've thought about that, and decided against. <code>needs_drop</code> might be observable, and I'd like the two versions to have the same API. Hopefully an inline no-op drop is easy to optimize away</p>



<a name="223541887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223541887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223541887">(Jan 21 2021 at 17:23)</a>:</h4>
<p>Good point. I think it affects build times more than the generated code.</p>



<a name="223543418"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PSA%3A%20we%20now%20can%20count%20things/near/223543418" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PSA.3A.20we.20now.20can.20count.20things.html#223543418">(Jan 21 2021 at 17:34)</a>:</h4>
<p>Yeah, its true that there will be extra fluff in debug, but hopefully not too much</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>